// import axios from 'axios'
let api = process.env.API_ROOT
let project_auth_api = process.env.PROJECT_AUTH_API

let BASE_URL = process.env.BASE_URL;
axios.interceptors.request.use(
    config => {
        if (config.url.includes('oss') || config.url.includes('jssdk')) {
            return config
        } else if (config.url.includes('Setprojectauth') || config.url.includes('freeAuth')) {
            config.url = project_auth_api + config.url
            return config
        }
        config.url = api + config.url
        return config
    }, err => {
        return Promise.reject(err)
    }
)

axios.interceptors.response.use(
    response => {
        if (response.data.status === 401) {
            let url = encodeURIComponent(window.location.href)
            window.location.href = "#/login?url=" + url
            // window.location.href = '#/login'
        } else if (response.data.status === 200 || response.data.code === 200) {
            return response
        } else {
            return Promise.reject(response.data.statusInfo)
        }
    },
    err =>{
        return Promise.reject(err)
    }
)

